package com.wuye.basic.controller;

import java.util.Arrays;
import java.util.Collections;
import java.util.List;
import javax.servlet.http.HttpServletResponse;

import com.wuye.basic.domain.dto.WyUnitInfoDTO;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.PutMapping;
import org.springframework.web.bind.annotation.DeleteMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import com.wuye.common.annotation.Log;
import com.wuye.common.core.controller.BaseController;
import com.wuye.common.core.domain.AjaxResult;
import com.wuye.common.enums.BusinessType;
import com.wuye.basic.domain.WyUnitInfo;
import com.wuye.basic.service.IWyUnitInfoService;
import com.wuye.common.utils.poi.ExcelUtil;
import com.wuye.common.core.page.TableDataInfo;

/**
 * 单元Controller
 * 
 * @author avalon
 * @date 2024-11-26
 */
@RestController
@RequestMapping("/basic/unitInfo")
public class WyUnitInfoController extends BaseController
{
    @Autowired
    private IWyUnitInfoService wyUnitInfoService;

    /**
     * 查询单元列表
     */
    @PreAuthorize("@ss.hasPermi('basic:unitInfo:list')")
    @GetMapping("/list")
    public TableDataInfo list(WyUnitInfo wyUnitInfo)
    {
        return wyUnitInfoService.selectInfo(wyUnitInfo);
    }

    /**
     * 导出单元列表
     */
    @PreAuthorize("@ss.hasPermi('basic:unitInfo:export')")
    @Log(title = "单元", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    public void export(HttpServletResponse response, WyUnitInfo wyUnitInfo)
    {
        List<WyUnitInfo> list = wyUnitInfoService.selectWyUnitInfoList(wyUnitInfo);
        ExcelUtil<WyUnitInfo> util = new ExcelUtil<WyUnitInfo>(WyUnitInfo.class);
        util.exportExcel(response, list, "单元数据");
    }

    /**
     * 获取单元详细信息
     */
    @PreAuthorize("@ss.hasPermi('basic:unitInfo:query')")
    @GetMapping(value = "/{id}")
    public AjaxResult getInfo(@PathVariable("id") Long id)
    {
        return success(wyUnitInfoService.getInfoById(id));
    }

    /**
     * 新增单元
     */
//    @PreAuthorize("@ss.hasPermi('basic:unitInfo:add')")
//    @Log(title = "单元", businessType = BusinessType.INSERT)
//    @PostMapping
//    public AjaxResult add(@RequestBody WyUnitInfo wyUnitInfo)
//    {
//        return toAjax(0);
//    }

    /**
     * 修改单元
     */
    @PreAuthorize("@ss.hasPermi('basic:unitInfo:edit')")
    @Log(title = "单元", businessType = BusinessType.UPDATE)
    @PutMapping
    public AjaxResult edit(@RequestBody WyUnitInfoDTO wyUnitInfoDTO)
    {
        return toAjax(wyUnitInfoService.edit(wyUnitInfoDTO));
    }

    /**
     * 删除单元
     */
    @PreAuthorize("@ss.hasPermi('basic:unitInfo:remove')")
    @Log(title = "单元", businessType = BusinessType.DELETE)
	@DeleteMapping("/{ids}")
    public AjaxResult remove(@PathVariable Long[] ids)
    {
        return toAjax(wyUnitInfoService.deleteBatchIds(Arrays.asList(ids)));
    }


    @GetMapping("/cascade")
    public AjaxResult cascade(){
        return AjaxResult.success(wyUnitInfoService.cascade());
    }
}
